package com.sanjiahantang.ythshopping.presenter;

import android.content.Context;

import com.sanjiahantang.ythshopping.config.ConfigValue;
import com.sanjiahantang.ythshopping.http.BaseDelegate;
import com.sanjiahantang.ythshopping.http.ExceptionHelper;
import com.sanjiahantang.ythshopping.http.OkHttpClientManager;
import com.sanjiahantang.ythshopping.model.OrderSubmitMsg;
import com.sanjiahantang.ythshopping.utils.Utils;
import com.sanjiahantang.ythshopping.views.OrderSubmitView;
import com.squareup.okhttp.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by admin on 2017/6/12.
 */

public class OrderSubmitPresenter extends BasePresenter{

    OrderSubmitView ordersubmitview;

    public OrderSubmitPresenter(OrderSubmitView ordersubmitview)
    {
        this.ordersubmitview=ordersubmitview;
    }

    public void getOSubmitMsg(final Context context, String money, String sid,String online ,String paytype)
    {
        initLoadDialog(context);
        mLoadingDialog.show();
        Map<String,String> params=new HashMap<>();
        params.put("key", ConfigValue.DATA_KEY);
        params.put("pay_money",money);
        params.put("sid",sid);
        params.put("online",online);
        if (online.equals("1"))
        {
            params.put("pay_id",paytype);
        }


        OkHttpClientManager.postAsyn(context, ConfigValue.APP_IP + "scan/orderSubmit", params, new BaseDelegate.ResultCallback<OrderSubmitMsg>() {
            @Override
            public void onError(Request request, Object tag, Exception e) {
                dismiss();
                Utils.showToast(context, ExceptionHelper.getMessage(e, context));
            }

            @Override
            public void onResponse(OrderSubmitMsg response, Object tag) {
                dismiss();
                ordersubmitview.getOrserSubmitMsg(response);
            }


        });

    }


}
